package com.katus.server.controller;

import com.katus.server.entity.Book;
import com.katus.server.entity.ResponseResult;
import com.katus.server.service.BookService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author SUN Katus
 * @version 1.0, 2021-07-12
 */
@Controller
@RequestMapping("/book")
@ResponseBody
@Slf4j
public class BookController {
    private final BookService bookService;

    @Autowired
    public BookController(BookService bookService) {
        this.bookService = bookService;
    }

    @GetMapping("/query")
    public ResponseResult<Integer> getBook(@RequestParam("num") Integer number) {
        log.info(number.toString());
        ResponseResult<Integer> result = new ResponseResult<>();
        result.setSuccess(true);
        result.setCode(0);
        result.setMessage("成功");
        result.setData(number);
        return result;
    }

    @PostMapping("/body")
    public ResponseResult<Book> bodyBook(@RequestBody Book book) {
        log.info(book.toString());
        ResponseResult<Book> result = new ResponseResult<>();
        result.setSuccess(true);
        result.setCode(0);
        result.setMessage("成功");
        result.setData(book);
        return result;
    }

    @PostMapping("/path/{type}")
    public ResponseResult<String> pathBook(@PathVariable("type") String type) {
        log.info(type);
        ResponseResult<String> result = new ResponseResult<>();
        result.setSuccess(true);
        result.setCode(0);
        result.setMessage("成功");
        result.setData(type);
        return result;
    }

    @PostMapping("/form")
    public ResponseResult<String> formBook(@ModelAttribute("id") String id) {
        log.info(id);
        ResponseResult<String> result = new ResponseResult<>();
        result.setSuccess(true);
        result.setCode(0);
        result.setMessage("成功");
        result.setData(id);
        return result;
    }
}
